package com.sport.facilities.booking.system.httptask;

import java.util.List;

import android.content.Context;
import android.util.Log;

import com.sport.facilities.booking.system.htmlchecker.ConfirmBookingPageChecker;
import com.sport.facilities.booking.system.model.Booking;

public class ConfirmBookingPageTask extends BasicTask {

	private final String TAG = "ConfirmBookingPageTask";

	public ConfirmBookingPageTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnGetConfirmBookingList() {
		try {
			super.onPreExecute();
			super.execute(PATH_CONFIRM_BOOK);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		Log.d(TAG, "onPostExecute");
		ConfirmBookingPageChecker cbChecker = new ConfirmBookingPageChecker();
		List<Booking> bookingList = null;
		try {
			bookingList = cbChecker.getConfirmBookingListfromHtml(result);
			this.listener.onTaskCompleted(bookingList);
		} catch (Exception e) {
			Log.e(TAG, "onPostExecuteException:" + e);
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}

	/*
	 * Special Logic only for PolyU Connection Here:
	 */

	public List<Booking> fnBookingConfirm() {
		return null;
	}

}
